import React from 'react';
import { inject, observer } from 'mobx-react';
import { Route, withRouter, Switch, Redirect } from 'react-router-dom';
import { TabPage , routeBackToUpperlevel , RouteLayout } from 'weaver-mobile-page';
import { Icon, Tools , ActionSheet , Modal , Bubble} from 'weaver-mobile';
import { toJS } from 'mobx';
import BaseIndex from '../base/index'
import MeetingSeatData from '../base/meetingSeat/meetingSeatData'
import TopicData from '../base/topic/topicData'
import ServiceData from '../base/service/serviceData'
import MemberIndex from '../base/member/index'
import SignIndex from '../base/sign/index'
import SignCreate from '../base/sign/signCreate'
import DiscussData from '../base/discuss/discussData'
import DecisionIndex from '../base/decision/index'
import Decision from '../base/decision/index'
import OverMeetingSet from '../base/overmeetingset/overMeetingSet'
import { isIOS } from '../../util/util';

const alert = Modal.alert;
const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;

@routeBackToUpperlevel
@inject('viewMeetingStore')
@withRouter
@observer
export default class Detail extends React.Component {
  constructor(props) {
      super(props);
      this.state = {
        nowTab:0,
        isDiscuss:false,
      };
  }

  componentWillMount() {
    const { initMeeting } = this.props.viewMeetingStore;
    initMeeting();
  }

  componentDidMount() {

    const {  viewMeetingStore:{setState, getPreview,getSignCreateSet, getBtns,initTopicAndServiceData}} = this.props;
    //查看的时候支持route两种形式/calendar/detail?meetingid=xx或者route.push({pathname:/calendar/detail,query{meetingid:xxx}})
    //如果是?meetingid=xxx的时候type一定是view
    //新增/编辑的时候只支持query的形式
    setState({topicViewActive:false,serviceViewActive:false})
    initTopicAndServiceData();
    const searchInfo = this.props.location.search ? this.props.location.search.split('?')[1]:''
    const search = searchInfo.length > 0 ?searchInfo.split('&'):[]
    let params = this.getQuery(search);
    if(params['meetingid']){
      sessionStorage.setItem('type','view')
      setState({type:'view'})
    }
    if(params['isDiscuss'] === '1'){
      getPreview({meetingid:params['meetingid']}, '', '', true);
      sessionStorage.setItem('meetingBaseTabs','')
      sessionStorage.setItem('isNormal','true')
      this.setState({isDiscuss:true})
    }
    if(params['type']==='create'){
      setState({createParams:params, urlCreateParams: params})
    }
    const meetingId = this.props.location.search ? params['meetingid']:(this.props.location&&this.props.location.query&&this.props.location.query.meetingid)
    getSignCreateSet({meetingid:meetingId});
    const isfromchatshare = params&& (params['isfromchatshare'] || '')
    const sharer = params&& (params['sharer'] || '')
    const type = this.props.location&&this.props.location.query&&this.props.location.query.type || params['type'];
    const roomPlanSelectDate = this.props.location&&this.props.location.query&&this.props.location.query.roomPlanSelectDate
    const meetingRoomBeginTime = this.props.location&&this.props.location.query&&this.props.location.query.meetingRoomBeginTime
    const meetingRoomEndTime = this.props.location&&this.props.location.query&&this.props.location.query.meetingRoomEndTime
    const address = this.props.location&&this.props.location.query&&this.props.location.query.address;
    type && sessionStorage.setItem('type', type)
    setState({
      meetingId:meetingId?meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):'',
      type:type?type:sessionStorage.getItem('type')?sessionStorage.getItem('type'):'view',
      roomPlanSelectDate:roomPlanSelectDate,
      begintime:meetingRoomBeginTime,
      endtime:meetingRoomEndTime,
      isfromchatshare:isfromchatshare,
      sharer:sharer,
      roomid: address
    })
    
    //根据sessionStorage中是否存在meetingBaseNowTab
    if(sessionStorage&&sessionStorage.meetingBaseNowTab){
      this.setState({ nowTab: parseInt(sessionStorage.meetingBaseNowTab,10) })
      setState({previewmeetingTab:parseInt(sessionStorage.meetingBaseNowTab,10)+1})
    }
    //因为所有tab都是走的自己的路由,但是btn需要和tab放在同一目录下面,所以要单独获取btn
    //获得btn
    getBtns({meetingid:meetingId?meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''})
    
    if(window.iNoBounce && !window.iNoBounce.isEnabled()) {
      isIOS() && window.iNoBounce.enable(); // 组件卸载后，还原解决ios滑动问题时的设置
    }
    if(search && search.length > 0) { // 通过URL直接进入详情页
      this.configNavigation(true);
      localStorage.setItem('meetingDetailIsSingle', 'true');
    } else {
      localStorage.removeItem('meetingDetailIsSingle');
    }
  }

  configNavigation = (bool, nextProps) => {
    if(!bool) {
      bool = localStorage.getItem('meetingDetailIsSingle') == 'true';
    }
    
    if(bool && window.em && window.em.configNavigation) {
      let noUrl = ["/calendar/detail/member/memberData/"];
      window.em.configNavigation({ // 配置导航栏-- http://192.168.1.241:8076/web/#/1?page_id=313
        'left':{
          'name': getLabel(384083,'返回'), 
          'action':function(argument){ 
            if(nextProps) {
              const { location:{ pathname: nP } } = nextProps;
              if(noUrl.some(v => nP.indexOf(v) > -1) || (nP.indexOf('/calendar/detail/') > -1 && nP.split('/').length > 4)) { // 判断是否为detail/下的一级子路由
                window.history.go(-1);
                return;
              }
            } 

            window.em.closeWindow&&window.em.closeWindow();
          },
          },//左侧按钮的名字 回调事件，回调的参数，单个事件
      });
    }
  }

  getQuery = (search)=>{
    let params ={}
    search.forEach((v,index)=>{
      const tempV = v.split('=')
      params[tempV[0]] = decodeURIComponent(tempV[1]) 
    });
    return params
  }

  componentWillReceiveProps (nextProps) {
    const prePath = this.props.location.pathname;
    const curPath = nextProps.location.pathname;
    if (curPath && curPath !== prePath) {
      this.setPage(curPath);
    }
    this.configNavigation(undefined, nextProps);
  }

  shouldComponentUpdate (nextProps){
    if(this.props.location.pathname === '/calendar/detail/addRequest' && nextProps.location.pathname === '/calendar/detail/addRequest'){
      return false
    }else{
      return true;
    }
  }

  componentWillUnmount () {
    // 卸载时,清空会议议程和会议服务中的数据
    const {overWriteOpenDoc,overWriteOpenWF,openDocFunc,openWFFunc,cleanStore} = this.props.viewMeetingStore;
    cleanStore();
    // cx end
    this.removesessionStorageItem();
    //是否需要还原openLink中的doc和workflow
    if(overWriteOpenDoc){
      window.openLink&&window.openLink.openDocument&&(window.openLink.openDocument = openDocFunc);
    }
    if(overWriteOpenWF){
      window.openLink&&window.openLink.openWorkflow&&(window.openLink.openWorkflow = openWFFunc);
    }
    if(window.em) { // 重置导航栏
      window.em.resetNavigation && window.em.resetNavigation();
    }
    localStorage.removeItem('meetingDetailIsSingle');
  }

  removesessionStorageItem = ()=>{
    sessionStorage.removeItem('meetingBaseNowTab');
    sessionStorage.removeItem('meetingBaseTabs');
    sessionStorage.removeItem('meetingName');
    sessionStorage.removeItem('meetingId');
    // sessionStorage.removeItem('type');
    sessionStorage.removeItem('showTopic');
    sessionStorage.removeItem('showService');
    sessionStorage.removeItem('showMeetingSeat');
    window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: '' })
  }

  setRealPath = (key)=>{
    let pathArr = JSON.parse(sessionStorage.getItem("meetingTabpath"))
    this.props.history.push(pathArr[key]);
  }

  setPage = (path) => {
    const { setState, } = this.props.viewMeetingStore;
    let showTopic = sessionStorage.getItem("showTopic")==="true"
    let showService = sessionStorage.getItem("showService")==="true"
    let showMeetingSeat = sessionStorage.getItem("showMeetingSeat")==="true"
    //isNormal代表是否为正常会议,还是草稿/待审批会议,这时候显示的不tab是不一致的
    const isNormal = sessionStorage.getItem('isNormal')
    let i = 0;
    let pathArr = JSON.parse(sessionStorage.getItem("meetingTabpath"))
    pathArr && pathArr.indexOf(path) >-1 && this.setState({ nowTab: pathArr.indexOf(path) - 1 }); 
    pathArr && pathArr.indexOf(path) >-1 && sessionStorage.setItem("meetingBaseNowTab",pathArr.indexOf(path)-1);
    //如果会议决议保存/提交后 pathArr中是没有对应的tab页签地址的,但是后续会存在
    if(pathArr && pathArr.indexOf(path) < 0 && path==='/calendar/detail/decisionData'){
      sessionStorage.setItem("meetingBaseNowTab",pathArr.length);
    }
    if(isNormal==='true'){
      if (path.indexOf('/calendar/detail/decisionData') > -1) { 
        setState({isView:'1'});
        sessionStorage.setItem("decisionIsView",'1');
        pathArr.indexOf('/calendar/detail/decisionData') > -1 && this.setState({nowTab:pathArr.length-2})
        pathArr.indexOf('/calendar/detail/decisionData') === -1 && this.setState({nowTab:pathArr.length-1})
      }
    }else{
      //非status == '0' || status == '1' || status == '3'的情况下已经不显示相关交流了,所以下面的代码无意义
      if (path.indexOf('/calendar/detail/discussData') > -1) { 
        this.setState({ nowTab: 4}); sessionStorage.setItem("meetingBaseNowTab",4); 
      }
    }
    
  }


   // 点击tab页切换
   changeTab = (tab,index) => {
    const { setPageNum , setState } = this.props.viewMeetingStore;
    const isNormal = sessionStorage.getItem('isNormal')
    if(this.state.isDiscuss){
      this.setState({isDiscuss:false})
    }
    if(tab.key !== 6){
      setPageNum(0)
    }
    let canChange = this.doTopicServiceCheck();
    if(canChange){
      switch(tab.key) {
        case 1: this.setPath(index, '/calendar/detail/index'); sessionStorage.setItem("meetingBaseNowTab",0); break;
        case 2: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        case 3: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        case 4: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        case 5: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        case 6: 
        this.setRealPath(tab.key)
          if(isNormal === 'true'){
            sessionStorage.setItem("meetingBaseNowTab",tab.key-1);
          }else{
            sessionStorage.setItem("meetingBaseNowTab",4);
          }
          break;
        case 7: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        case 8: 
          this.setRealPath(tab.key)
          sessionStorage.setItem("meetingBaseNowTab",tab.key-1); 
          break;
        // default:this.setPath(index, '/calendar/detail/index'); sessionStorage.setItem("meetingBaseNowTab",0); break;
      }
      this.onChangeTab(tab.key)
    }
    
  }

  doTopicServiceCheck = ()=>{
    const { type, previewmeetingTab, topic_list, service_list } = this.props.viewMeetingStore;
    let canChange = true;
    if(type === 'create' || type === 'edit'){
      if(previewmeetingTab === 2){
        topic_list.doValidate(
          (pass, id, result) => {
            if (!pass) {
              canChange = false
              this.setState({nowTab:1})
              // 如果校验失败
              const form = topic_list.formList[id]; // 获取报错的form
              const { message, domkey } = result;
              topic_list.setState({ editingKey: id });
              this.props.history.push(topic_list.pathToEditor); // 跳转到编辑页面
              setTimeout(() => { // 等待页面渲染
                Bubble.error(message, 1, { top: '50%' }); // 错误提示
                form.focusField(domkey); // 定位到错误项
              }, 200);
              return;
            }
          },
        )
      }
      if(previewmeetingTab === 3){
        service_list.doValidate(
          (pass, id, result) => {
            if (!pass) {
              canChange = false
              this.setState({nowTab:2})
              // 如果校验失败
              const form = service_list.formList[id]; // 获取报错的form
              const { message, domkey } = result;
              service_list.setState({ editingKey: id });
              this.props.history.push(service_list.pathToEditor); // 跳转到编辑页面
              setTimeout(() => { // 等待页面渲染
                Bubble.error(message, 1, { top: '50%' }); // 错误提示
                form.focusField(domkey); // 定位到错误项
              }, 200);
              return;
            }
          },
        )
      }
    }
    
    return canChange
  }

  onChangeTab = (e) => {
    const { setState } = this.props.viewMeetingStore;
    setState({previewmeetingTab:e});
    if(e == '2'){
			setState({topicViewActive:true});
		}
		if(e == '3'){
      setState({serviceViewActive:true});
		}
  }

  setPath = (key, path) => {
    this.props.history.push(path);
  }

  render() {
    const { noRight, noData,noSecretRight,type, tabPanes, setState, isDecision,onlyFlowCreate, hideCreateEntry, workflowBaseIds,requestFieldIds,addRequestUrlParams,renderToDecision,previewMeetingResultInfo } = this.props.viewMeetingStore;
    // const { onlyFlowCreate, hideCreateEntry, workflowBaseIds,requestFieldIds,} = this.props.viewMeetingStore;
    let typeTemp = type?type:sessionStorage.getItem('type')?sessionStorage.getItem('type'):'view';
    let workflowBaseIdsArr = workflowBaseIds.split(',')
    let baseBtns = this.getBtns();
    if(window.rewriteMeetingBtnGroup && typeof window.rewriteMeetingBtnGroup == 'function') {
      baseBtns = window.rewriteMeetingBtnGroup(baseBtns, {...this.props});
    }

    if(tabPanes.length == 0 && sessionStorage.meetingBaseTabs){
      setState({tabPanes:JSON.parse(sessionStorage.meetingBaseTabs)})
    }
    let redirectPathName = '/calendar/detail/index'
    let pageTemp = -1;//用于判断打开相关交流页面的tab
    if(this.state.isDiscuss){
      redirectPathName = '/calendar/detail/discussData'
      if(isDecision){
        pageTemp = tabPanes.length-2
      }else{
        pageTemp = tabPanes.length-1
      }
    }
    // if(renderToDecision){
    //   pageTemp = tabPanes.length
    // }
    if(typeTemp === 'create' && this.props.history.action !== 'POP'){
      if(hideCreateEntry == 1){
        return <div className='no-right'>
              <div className='icon-noright'>
                <Icon type='wuquanxian' size='lg'/>
              </div>
              <div className='message'>
              {getLabel(510049, '请通过流程新建会议！')}
              </div>
            </div>
      }else if(onlyFlowCreate == 1 && hideCreateEntry ==0 &&  workflowBaseIdsArr.length === 1 && workflowBaseIdsArr[0] === ''){
        return <div className='no-right'>
        <div className='icon-noright'>
          <Icon type='wuquanxian' size='lg'/>
        </div>
        <div className='message'>
          {getLabel(510148, '系统查找不到新建会议流程！')}
        </div>
      </div>
      }
      else if(onlyFlowCreate == 1 && hideCreateEntry ==0 && workflowBaseIdsArr.length === 1){
        redirectPathName = `/calendar/detail/createRequest`;
      }else if(onlyFlowCreate == 1 && hideCreateEntry ==0 && workflowBaseIdsArr.length > 1){
        redirectPathName = `/calendar/detail/addRequest`;
      }
    }
    if(pageTemp < 0){
      pageTemp = this.state.nowTab
    }
    const tabProps = {
      onTabClick: (tab,index) => { this.changeTab(tab,index) },
      page:pageTemp
    };
    const defaultTabBarProps = {
      activeTab:pageTemp,
    }
    return (
      tabPanes&&<div style={{height:'100%'}} isviewtab={previewMeetingResultInfo && previewMeetingResultInfo.isViewTab}>
        {noRight?<div className='no-right'>
          <div className='icon-noright'>
            <Icon type='wuquanxian' size='lg'/>
          </div>
          <div className='message'>
            {getLabel(2012,'对不起，您暂时没有权限！')}
          </div>
        </div>:noData?<div className='no-right'>
          <div className='icon-noright'>
            <Icon type='wuquanxian' size='lg'/>
          </div>
          <div className='message'>
            {getLabel(508093,'该会议已被删除！')}
          </div>
        </div>:noSecretRight?<div className='no-right'>
          <div className='icon-noright'>
            <Icon type='wuquanxian' size='lg'/>
          </div>
          <div className='message'>
            {getLabel(501082 ,'对不起，您的人员密级不足以查看该内容')}
          </div>
        </div>:tabPanes&&<TabPage
          className={type==='view' ? 'preview-meeting-tabs' : 'nopreview-meeting-tabs'}
          tabs={tabPanes}
          tabProps={tabProps}
          defaultTabBarProps={defaultTabBarProps}
        />}
        {!noRight&&!noData&&!noSecretRight&&tabPanes&&<div className={baseBtns.length > 0?'tabContentHeight-container meeting-detail-container':'tabContentHeight-container2 meeting-detail-container'}>
        <Switch>
          <Route
            key="index"
            path="/calendar/detail/index"
            render={()=>{ return <BaseIndex />}}
          />
          <Route
            key="meetingSeatData"
            path="/calendar/detail/meetingSeatData"
            render={()=>{ return <MeetingSeatData />}}
          />
          <Route
            key="topicData"
            path="/calendar/detail/topicData"
            render={()=>{ return <TopicData />}}
          />
          <Route
            key="serviceData"
            path="/calendar/detail/serviceData"
            render={()=>{ return <ServiceData />}}
          />
          <Route
            key="memberData"
            path="/calendar/detail/member"
            render={()=>{ return <MemberIndex />}}
          />
          <Route
            key="signData"
            path="/calendar/detail/sign"
            render={()=>{ return <SignIndex />}}
          />
            <Route
              key="signCreate"
              path="/calendar/detail/signcreate"
              render={() => { return <SignCreate /> }}
            />
            <Route
              key="overMeetingSet"
              path="/calendar/detail/overmeetingset/overMeetingSet"
              render={() => (
                <RouteLayout>
                  <div key="decisoinDiv" className="wm-route-layout wm-demo-route-layout-page route-div-height">
                  <OverMeetingSet />
                  </div>
                </RouteLayout>
              )}
            />
            <Route
            key="discussData"
            path="/calendar/detail/discussData"
            render={()=>{ return <DiscussData />}}
          />
          <Route
            key="decisionData"
            path="/calendar/detail/decisionData"
            render={()=>{ return <DecisionIndex />}}
          />
          <Route
            key="decisoin"
            path="/calendar/detail/decision/index"
            render={()=>(
              <RouteLayout>
              <div key="decisoinDiv" className="wm-route-layout wm-demo-route-layout-page route-div-height">
                <Decision />
              </div>
              </RouteLayout>
            )}
          />
          <RouteLayout.Frame
            id="createRequestFrame"
            path={'/calendar/detail/createRequest'}
            iframeProps={{
              src: `/spa/workflow/static4mobileform/index.html#/req?iscreate=1&workflowid=${workflowBaseIds}${addRequestUrlParams}`,
            }}
          />
          <RouteLayout.Frame
            id="addRequestFrame"
            path={'/calendar/detail/addRequest'}
            iframeProps={{
              src: `/spa/workflow/static4mobile/index.html#/add?isNeedTab=0&wfRange=${workflowBaseIds}${addRequestUrlParams}`,
            }}
          />
          
          <Redirect exact path="/calendar/detail" to={{pathname: redirectPathName}} />
          </Switch>
          </div>}
          {
            baseBtns.length > 0 && 
            type==='create'?<div><ButtonGroup data={baseBtns}/>
            </div>:
            <div className={'detail-footer'}><ButtonGroup data={baseBtns} defProps={{ store: this.props.viewMeetingStore}}/>
            </div>
          }
      </div>
    );
  }

  getBtns = (compo='button')=>{
    const { btns , meetingId , onLoading, tabs } = this.props.viewMeetingStore;
    let baseBtns = [];
    const type = sessionStorage.getItem('type')
    if(type === 'view'){
      //和徐汝晶确认过,普通参会用户在查看页面只能查看/填写回执
      const showEditbtn = btns
      if(showEditbtn && btns.length > 0){
          if(btns.length>2){
            //两个按钮
            baseBtns = this.getViewButton(btns.slice(0,2),'button',meetingId)
            //获得更多按钮中的数据
            const actionSheet = this.getViewButton(btns,'actionSheet',meetingId)
            baseBtns.push(
              {
                key: 'more',
                disabled:onLoading,
                text: getLabel(17499, '更多'),
                onClick: () => {this.showActionSheet(actionSheet)},
              }
            )
          }else{
            baseBtns = this.getViewButton(btns,'button',meetingId)
          }
      }else{
        if (tabs && tabs.member) {
          baseBtns = this.showReceiptButton();
        }
      }
    }else if(type === 'create'){
      baseBtns=[
        {
          key: 'add',
          text: getLabel(220, '草稿'),
          disabled:onLoading,
          onClick: () => {this.handleSubmit( 'save', meetingId)},
        },
        {
          key: 'submit',
          text: getLabel(725, '提交'),
          type: 'primary',
          disabled:onLoading,
          onClick: () => {this.handleSubmit('submit', meetingId)},
        },
      ]
    }else if(type === 'edit'){
      baseBtns=[
        {
          key: 'save',
          text: getLabel(30986, '保存'),
          disabled:onLoading,
          onClick: () => {this.handleSubmit('edit', meetingId)},
        },
      ]
    }else if(type === 'change'){
      baseBtns=[
        {
          key: 'change',
          text: getLabel(725, '提交'),
          disabled:onLoading,
          onClick: () => {this.handleSubmit('change', meetingId)},
        },
      ]
    }
    return baseBtns;
  }

  showActionSheet = (buttons) => {
    if(window.rewriteMeetingActionSheet && typeof window.rewriteMeetingActionSheet == 'function') {
      buttons = window.rewriteMeetingActionSheet(buttons, {...this.props});
    }
    ActionSheet.showActionSheetWithOptions({
      options: buttons,
      cancelButtonIndex: buttons.length - 1,
      maskClosable: true,
      'data-seed': 'logId',
      defProps: this.props.viewMeetingStore
      // wrapProps,
    })
  }
  pieCallBack = (key)=>{
    const { history } = this.props;
    if(key === 'overMeetingSet'){
      history.push("/calendar/detail/overmeetingset/overMeetingSet");
    } 
  }

  getViewButton = (btns,type='button',meetingId='')=>{
    const { onLoading, tabs, setState, editTopicLayout, get_Conditions, get_Data, accessoryBaseInfo, arrangeTopicParams } = this.props.viewMeetingStore;
    const { pathname } = this.props.location;
    let baseBtns = [];
    const arrangeTopic = () => {
      setState({ topicType: 'edit' }, () => {
        get_Conditions({meetingid: meetingId, secId:accessoryBaseInfo.category, ...arrangeTopicParams}, 'topic', () => {
          this.props.history.push(editTopicLayout.path);
        });
        get_Data({meetingid: meetingId, ...arrangeTopicParams}, 'topic');
      });
    };
    if(type ==='button'){
      btns.some((element) => {
        return element === 'doEdit'
      }) &&
      baseBtns.push({
        key: 'edit',
        text: getLabel(26473, '编辑'),
        disabled:onLoading,
        onClick: () => {this.getEdit()},
      });
      btns.some((element) => {
        return element === 'reSubmit2'
      }) &&
      baseBtns.push({
        key: 'reSubmit2',
        text: getLabel(725, '提交'),
        disabled:onLoading,
        onClick: () => {this.handleSubmit('reSubmit2', meetingId)},
      });
      btns.some((element) => {
        return element === 'changeMeeting'
      }) &&
      baseBtns.push({
        key: 'changeMeeting',
        text: getLabel(384487, '变更会议'),
        disabled:onLoading,
        onClick: () => {this.changeMeeting()},
      });

      btns.some((element) => {
        return element === 'onShowDecision'
      }) &&
      baseBtns.push({
        key: 'onShowDecision',
        text: getLabel(2194, '会议决议'),
        disabled:onLoading,
        onClick: () => {this.onShowDecision()}, 
      });

      btns.some((element) => {
        return element === 'overMeeting'
      }) &&
        baseBtns.push({
          key: 'overMeeting',
          text: getLabel(126003, '提前结束'),
          disabled: onLoading,
          onClick: () => {this.pieCallBack('overMeetingSet')},
        });
      btns.some((element) => {
        return element === 'copyNewMeeting'
      }) &&
      baseBtns.push({
        key: 'copyNewMeeting',
        text: getLabel(77, '复制'),
        disabled:onLoading,
        onClick: () => {this.copy(meetingId)},
      });
      btns.some((element) => {
        return element === 'cancelMeeting'
      }) &&
      baseBtns.push({
        key: 'cancelMeeting',
        text: getLabel(20115, '取消会议'),
        disabled:onLoading,
        onClick: () => {this.cancelMeeting(meetingId)},
      });
      btns.some((element) => {
        return element === 'doSubmit'
      }) &&
      baseBtns.push({
        key: 'doSubmit',
        text: getLabel(142, '批准'),
        disabled:onLoading,
        onClick: () => {this.handleSubmit('doSubmit', meetingId)},
      });
      btns.some((element) => {
        return element === 'doSubmit2'
      }) &&
      baseBtns.push({
        key: 'doSubmit2',
        text: getLabel(15143, '提交审批'),
        disabled:onLoading,
        onClick: () => {this.handleSubmit('doSubmit2', meetingId)},
      });
      btns.some((element) => {
        return element === 'doReject'
      }) &&
      baseBtns.push({
        key: 'doReject',
        text: getLabel(236, '退回'),
        disabled:onLoading,
        onClick: () => {this.doReject(meetingId)},
      });
      btns.some((element) => {
        return element === 'reSubmit'
      }) &&
      baseBtns.push({
        key: 'reSubmit',
        text: getLabel(15143, '提交审批'),
        disabled:onLoading,
        onClick: () => {this.handleSubmit('reSubmit', meetingId)},
      });
      btns.some((element) => {
        return element === 'doDelete'
      }) &&
      baseBtns.push({
        key: 'doDelete',
        text: getLabel(91, '删除'),
        disabled:onLoading,
        onClick: () => {this.doDelete(meetingId)},
      });

      btns.some((element) => {
        return element === 'receiptBtn'
      }) &&
      baseBtns.push({
        key: 'receiptBtn',
        text: getLabel(500586,'提交回执'),
        disabled:onLoading,
        onClick: () => {},
      })
      pathname.indexOf('detail/topicData') > -1 && btns.some((element) => {
        return element === 'showTidy'
      }) &&
      baseBtns.push({
        key: 'showTidy',
        text: getLabel('519704','整理议程'),
        disabled:onLoading,
        onClick: () => {
          arrangeTopic();
        },
      })

    }else if(type==='actionSheet'){
      btns.some((element) => {
        return element === 'doEdit'
      }) &&
      baseBtns.push({
        content: getLabel(26473, '编辑'),
        onClick: () => {this.getEdit()},
      });
      btns.some((element) => {
        return element === 'reSubmit2'
      }) &&
      baseBtns.push({
        content: getLabel(725, '提交'),
        onClick: () => {this.handleSubmit('reSubmit2', meetingId)},
      });
      btns.some((element) => {
        return element === 'changeMeeting'
      }) &&
      baseBtns.push({
        content: getLabel(384487, '变更会议'),
        onClick: () => {this.changeMeeting()},
      });
      btns.some((element) => {
        return element === 'onShowDecision'
      }) &&
      baseBtns.push({
        content: getLabel(2194, '会议决议'),
        onClick: () => {this.onShowDecision()},
      });
      btns.some((element) => {
        return element === 'overMeeting'
      }) &&
        baseBtns.push({
          content: getLabel(126003, '提前结束'),
          onClick: () => {this.pieCallBack('overMeetingSet')},
        });
      btns.some((element) => {
        return element === 'copyNewMeeting'
      }) &&
      baseBtns.push({
        content: getLabel(77, '复制'),
        onClick: () => {this.copy(meetingId)},
      });
      btns.some((element) => {
        return element === 'cancelMeeting'
      }) &&
      baseBtns.push({
        content: getLabel(20115, '取消会议'),
        onClick: () => {this.cancelMeeting(meetingId)},
      });
      btns.some((element) => {
        return element === 'doSubmit'
      }) &&
      baseBtns.push({
        content: getLabel(142, '批准'),
        onClick: () => {this.handleSubmit('doSubmit', meetingId)},
      });
      btns.some((element) => {
        return element === 'doSubmit2'
      }) &&
      baseBtns.push({
        content: getLabel(15143, '提交审批'),
        onClick: () => {this.handleSubmit('doSubmit2', meetingId)},
      });
      btns.some((element) => {
        return element === 'doReject'
      }) &&
      baseBtns.push({
        content: getLabel(236, '退回'),
        onClick: () => {this.doReject(meetingId)},
      });
      btns.some((element) => {
        return element === 'reSubmit'
      }) &&
      baseBtns.push({
        content: getLabel(15143, '提交审批'),
        onClick: () => {this.handleSubmit('reSubmit', meetingId)},
      });
      btns.some((element) => {
        return element === 'doDelete'
      }) &&
      baseBtns.push({
        content: getLabel(91, '删除'),
        onClick: () => {this.doDelete(meetingId)},
      });

      btns.some((element) => {
        return element === 'receiptBtn'
      }) &&
      baseBtns.push({
        content: getLabel(500586,'提交回执'),
        onClick: () => {this.openReceipt(meetingId)},
      });

      pathname.indexOf('detail/topicData') > -1 && btns.some((element) => {
        return element === 'showTidy'
      }) &&
      baseBtns.push({
        key: 'showTidy',
        content: getLabel('519704','整理议程'),
        onClick: () => {
          arrangeTopic();
        },
      })

      // btns.some((element) => {
      //   return element === 'chanageSignBackTime'
      // }) &&
      //   baseBtns.push({
      //     content: getLabel(514149, '设置签到/签退时间'),
      //     onClick: () => { this.openSetSignTime() },
      //   });

      baseBtns.push({
        content: getLabel(386789,'取消'),
      })
    }

    return baseBtns;

  }


    //设置签到/签退时间
    openSetSignTime = () => {
      const { history } = this.props;
      const { getDefaultSignBackTime, toSetSignTime } = this.props.viewMeetingStore;
      // getDefaultSignBackTime();
      history.push('/calendar/detail/sign/setSignTime')
    }
  //参会回执
  openReceipt = (params) =>{
    const { history } = this.props;
    const { setState  } = this.props.viewMeetingStore;
    setState({memberPage:0,memberType:1})
    sessionStorage.setItem('meetingMemberNowTab',0)
    sessionStorage.setItem('meetingMemberType',1)
    history.push('/calendar/detail/member/memberData/allMember');
  }

  handleSubmit = (type = 'submit', meetingId = '', callback) => {
    this.setOnLoading(true)
    //获取所需要的数据
    const { form, topic_data, serivce_data, serviceKeycol,signCreateForm } = this.props.viewMeetingStore;
    let canSubmit = true;
    if(type === 'save' || type === 'submit' || type === 'edit'){
      canSubmit = this.doTopicServiceCheck();
      if(!canSubmit){
        this.setOnLoading(false)
      }
    }
    let topic = [];
    let service = [];
    let signCreate = [];
    const valuesTemp = form.formParams
    const signCreateTepm = signCreateForm.formParams;
    if (canSubmit) {
      canSubmit = valuesTemp.address || valuesTemp.customizeAddress;
      if (!canSubmit) {
        alert(getLabel(15172, '系统提示'), getLabel(384779,'会议地点、自定义会议地点，必须填写一个'), [
          { text: getLabel(386788,'确定'), onPress: () => {this.setOnLoading()} },
        ]);
        return;
      }
      // if(canSubmit){
      //   canSubmit = valuesTemp.hrmmembers || valuesTemp.hrmDepartments || valuesTemp.hrmSubCompanys;
      // }
      // if (!canSubmit) {
      //   alert(getLabel(15172, '系统提示'), getLabel(512362,'参会人员、参会部门、参会分部请至少选择1个！'), [
      //     { text: getLabel(386788,'确定'), onPress: () => {this.setOnLoading()} },
      //   ]);
      //   return;
      // }
    }
    let values = {...valuesTemp}
    topic_data && topic_data.forEach((res,row) => { // 会议议程
      let index = row + 1;
      Object.keys(res).forEach(key => {
        if(typeof res[key] == 'object'){
          try{
            let fileids = res[key]&&res[key].map(_v=>{
              return _v.fileid
            })
            service[key+'_'+index] = fileids.join(',');
          }catch(e){

          }
          
        }else{
          topic[key+'_'+index] = res[key];
        }
      })
      topic['topicrows'] = index || 0;
    })
    serivce_data && serivce_data.forEach((res,row) => { // 会议服务
      let index = row + 1;
      Object.keys(res).forEach(key => {
        if(typeof res[key] == 'object'){
          try{
            let fileids = res[key]&&res[key].map(_v=>{
              return _v.fileid
            })
            service[key+'_'+index] = fileids.join(',');
          }catch(e){

          }
          
        }else{
          service[key+'_'+index] = res[key];
        }
        
      })
      service['servicerows'] = index || 0;
    })
    values = { ...values, ...topic, ...service,...signCreateTepm };  // 会议议程和会议服务数据
   // values = {...values,...topic, ...service};  // 会议议程和会议服务数据
    
    let {servicerows} = {...values}
    let servicearr = [];
    if(servicerows > 0){
      for (let key in values) {
        if (key.indexOf(`${serviceKeycol}_`) == 0) {
          servicearr.push(values[key])
        }
      }
    }
    let servicearrcopy = servicearr.filter((e, index, self) => {
      return self.indexOf(e) == index
    })
    values = {...values, serviceitems: servicearrcopy.join(',')}
    canSubmit && this.formValidate(values,type,meetingId,callback)
  }

  formValidate = (allCreateDatas, type, meetingId, callback)=>{
    const {previewmeetingTab, form, ecCallerVisible,meetingTopicDefaultValue,meetingServiceDefaultValue,topicViewActive,serviceViewActive } = this.props.viewMeetingStore;
    let validResult = form.doValidate();
    if(validResult.pass){
      let checkTime = this.checkTime(allCreateDatas); //checkTime为true可以继续提交
      let checkRemind = this.checkRemind(allCreateDatas);
      if(!checkTime){
        alert(getLabel(15172, '系统提示'), getLabel(31832,'结束时间必须大于开始时间'), [
          { text: getLabel(386788,'确定'), onPress: () => {this.setOnLoading()} },
        ]);
      }else if(!checkRemind){
        alert(getLabel(15172, '系统提示'), getLabel(83128,'请选择提醒时间'), [
          { text: getLabel(386788,'确定'), onPress: () => {this.setOnLoading()} },
        ]);
      }else{
        if (callback && typeof(callback) === 'function') {//tab页切换校验成功，切换tab，不提交
          callback()
        } else if(!topicViewActive && (type === 'save' || type === 'submit') && meetingTopicDefaultValue == 1){
          this.setOnLoading(false)
          this.onChangeTab(2);
          this.setRealPath(2)
          sessionStorage.setItem("meetingBaseNowTab",1); 
          Bubble.error(`${getLabel(384010, '存在必填项未填写')}`,1,{ top: '50%' });
          this.doTopicServiceCheck()
        } else if(!serviceViewActive && (type === 'save' || type === 'submit') && meetingServiceDefaultValue == 1){
          this.setOnLoading(false)
          this.onChangeTab(3);
          this.setRealPath(3)
          sessionStorage.setItem("meetingBaseNowTab",2); 
          Bubble.error(`${getLabel(384010, '存在必填项未填写')}`,{ top: '50%' });
          this.doTopicServiceCheck()
        }else{
          let chkParams = ecCallerVisible ? {hrmmembers:allCreateDatas.hrmmembers,
            crmmembers:allCreateDatas.crmmembers,
            address:allCreateDatas.address,
            serviceitems:allCreateDatas.serviceitems,
            begindate:allCreateDatas.begindate,
            begintime:allCreateDatas.begintime,
            enddate:allCreateDatas.enddate,
            endtime:allCreateDatas.endtime,
            caller:allCreateDatas.caller,
            contacter:allCreateDatas.contacter,
            requestid:allCreateDatas.requestid,
            meetingid:allCreateDatas.meetingid,}
            :{
              hrmmembers:allCreateDatas.hrmmembers,
              crmmembers:allCreateDatas.crmmembers,
              address:allCreateDatas.address,
              serviceitems:allCreateDatas.serviceitems,
              begindate:allCreateDatas.begindate,
              begintime:allCreateDatas.begintime,
              enddate:allCreateDatas.enddate,
              endtime:allCreateDatas.endtime,
              contacter:allCreateDatas.contacter,
              requestid:allCreateDatas.requestid,
              meetingid:allCreateDatas.meetingid,
            } 
          this.chkMeeting(chkParams,allCreateDatas, type, meetingId);
        }
      }
    }else{
      this.setOnLoading();
    }
  }

  checkTime = (allCreateDatas) => {
    let {begindate, enddate, begintime, endtime} = allCreateDatas;
    if (begindate > enddate) {
      return false;
    } else if (begindate === enddate && begintime >= endtime) {
      return false;
    } else {
      return true;
    }
  }

  checkRemind = (allCreateDatas) => {
    const { getFormBrowserType } = this.props.viewMeetingStore;
    if(getFormBrowserType('remindTypeNew') === 'INPUT'){
      return true;
    }
    let {remindTypeNew, remindImmediately,remindBeforeEnd,remindBeforeStart} = allCreateDatas;
    if (remindTypeNew && remindTypeNew !== ''  && 
    (remindImmediately === '0' || !remindImmediately) && 
    (remindBeforeEnd === '0' || !remindBeforeEnd) && 
    (remindBeforeStart ==='0' || !remindBeforeStart)) {
      return false;
    } else {
      return true;
    }
  }

  chkMeeting = (chkParams,allCreateDatas, type, meetingId) => {
    const { chkMeeting,customMeetingChk,customField } = this.props.viewMeetingStore;
    allCreateDatas = {...allCreateDatas,meetingid:meetingId}
	if(customField.length > 0){
        customField.forEach((v,index)=>{
          allCreateDatas[v]!=undefined?chkParams[v]=allCreateDatas[v]:''
        })
    }
    chkParams = {...chkParams,meetingid:meetingId}
    customMeetingChk(chkParams).then((result)=>{
      if(result.chkstatus){
        chkMeeting(chkParams).then((result) => {
          if (!result.address.chkstatus) {
            this.doAddressTip(allCreateDatas, result, type, meetingId)
          } else if (!result.member.chkstatus) {
            this.doMemberTip(allCreateDatas, result, type, meetingId)
          } else if (!result.wpMember.chkstatus) {
            this.doWPMemberTip(allCreateDatas, result, type, meetingId)
          } else if (!result.service.chkstatus) {
            this.doServiceTip(allCreateDatas, result, type, meetingId)
          } else {
            //走提交接口
            this.doCreateSubmit(allCreateDatas, type, meetingId)
          }
        })
      }else{
        if(result.isForbidden){
          alert(getLabel(15172, '系统提示'), result.msg, [
            {
              text: getLabel(386788,'确定'), 
              onPress: () => {
                this.setOnLoading()
              }, 
              style: 'default' 
            },
          ])
        }else{
          alert(getLabel(15172, '系统提示'), result.msg, [
            {
              text: getLabel(386789,'取消'), 
              onPress: () => {
                this.setOnLoading()
              },
              style: 'default' 
            },
            {
              text: getLabel(386788,'确定'), 
              onPress: () => {
                chkMeeting(allCreateDatas).then((result) => {
                  if (!result.address.chkstatus) {
                    this.doAddressTip(allCreateDatas, result, type, meetingId)
                  } else if (!result.member.chkstatus) {
                    this.doMemberTip(allCreateDatas, result, type, meetingId)
                  } else if (!result.wpMember.chkstatus) {
                    this.doWPMemberTip(allCreateDatas, result, type, meetingId)
                  } else if (!result.service.chkstatus) {
                    this.doServiceTip(allCreateDatas, result, type, meetingId)
                  } else {
                    //走提交接口
                    this.doCreateSubmit(allCreateDatas, type, meetingId)
                  }
                })
              } 
            },
          ])
        }
      }
    })
  }

  doAddressTip = (allCreateDatas, result, type, meetingId) => {
    let that = this
    let conMsg = result.address.msg.map((e) => {
      return <div>{`[${e}]`}{getLabel(127867, '冲突')}</div>
    })
    let addressConflictMsg=<div className={'meeting-check-contain'}>
        {conMsg}
    </div>
    if (result.address.cansub === true) {//冲突了是否可提交，true是可提交
      alert(getLabel(384773, '会议室冲突'), addressConflictMsg, [
        {
          text: getLabel(386789,'取消'), 
          onPress: () => {
            this.setOnLoading()
          },
          style: 'default' 
        },
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            if (!result.member.chkstatus) {
              that.doMemberTip(allCreateDatas, result, type, meetingId)
            } else if (!result.wpMember.chkstatus) {
              that.doWPMemberTip(allCreateDatas, result, type, meetingId)
            } else if (!result.service.chkstatus) {
              that.doServiceTip(allCreateDatas, result, type, meetingId)
            } else {
              //走接口
              that.doCreateSubmit(allCreateDatas, type, meetingId)
            }
          } 
        },
      ])
    } else {
      alert(getLabel(32875, '会议室冲突不能提交'), conMsg, [
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
      ])
    }
  }

  doMemberTip = (allCreateDatas, result, type, meetingId) => {
    let that = this
    let cont = result.member.msg.hrms.map((e) => {
      return <div>{e}</div>
    })
    let contcrms = result.member.msg.crms.map((e) => {
      return <div>{e}</div>
    })
    let memberCrmMsg=<div className={'meeting-check-contain'}>
        {result.member.msg.hrms.length > 0 ? <div>{getLabel(30042, '人员')}：{cont}</div> : ''}
        {result.member.msg.crms.length > 0 ? <div>{getLabel(136, '客户')}：{contcrms}</div> : ''}
    </div>

    if (result.member.cansub === true) {
      alert(getLabel(384775, '参会人员冲突'), memberCrmMsg, [
        {
          text: getLabel(386789,'取消'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            if (!result.wpMember.chkstatus) {
              that.doWPMemberTip(allCreateDatas, result, type, meetingId)
            }else if (!result.service.chkstatus) {
              that.doServiceTip(allCreateDatas, result, type, meetingId)
            } else {
              //走接口
              that.doCreateSubmit(allCreateDatas, type, meetingId)
            }
          } 
        },
      ])
    } else {
      alert(getLabel(384776, '参会人员冲突不能提交'), memberCrmMsg, [
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
      ])
    }
  }

  doWPMemberTip = (allCreateDatas, result, type, meetingId) => {
    let that = this
    let cont = result.wpMember.msg.hrms.map((e) => {
      return <div>{e}</div>
    })
    
    let memberCrmMsg=<div className={'meeting-check-contain'}>
        {cont}
    </div>

    if (result.wpMember.cansub === true) {
      alert(getLabel(517068, '以下参会人员存在日程冲突，确定要继续保存吗？'), memberCrmMsg, [
        {
          text: getLabel(386789,'取消'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
          if (!result.service.chkstatus) {
              that.doServiceTip(allCreateDatas, result, type, meetingId)
            } else {
              //走接口
              that.doCreateSubmit(allCreateDatas, type, meetingId)
            }
          } 
        },
      ])
    } else {
      alert(getLabel(516987, '参会人日程冲突不能保存'), memberCrmMsg, [
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
      ])
    }

  }

  doServiceTip = (allCreateDatas, result, type, meetingId) => {
    let that = this;
    let conMsg = result.service.msg.map((e) => {
      return <div>{`${e}`}{getLabel(127867, '冲突')}</div>
    })
    let serviceConflictMsg = <div>{conMsg}</div>
    if (result.service.cansub === true) {
      alert(getLabel(384777, '会议服务冲突'), serviceConflictMsg, [
        {
          text: getLabel(386789,'取消'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            //走接口
            that.doCreateSubmit(allCreateDatas, type, meetingId)
          } 
        },
      ])
    } else {
      alert(getLabel(128456, '会议服务冲突，不能提交！'), serviceConflictMsg, [
        {
          text: getLabel(386788,'确定'), 
          onPress: () => {
            this.setOnLoading()
          }, 
          style: 'default' 
        },
      ])
    }
  }

  doCreateSubmit = (allCreateDatas, type, meetingId) => {
    if(type==='submit'){
      this.submit(allCreateDatas)
    }else if(type==='save'){
      this.save(allCreateDatas)
    }else if(type==='edit'){
      this.edit(allCreateDatas)
    }else if(type==='change'){
      this.submitChangeMeeting(allCreateDatas)
    }else if(type==='reSubmit'){
      this.reSubmit(meetingId)
    }else if(type==='reSubmit2'){
      this.reSubmit2(meetingId)
    }else if(type==='doSubmit'){
      this.doSubmit(meetingId)
    }else if(type==='doSubmit2'){
      this.doSubmit2(meetingId)
    }
  }

  showReceiptButton = ()=>{
    const { showReceipt } = this.props.viewMeetingStore;
    const pathname = this.props.location.pathname;
    let receiptBtn = [];
    //相关交流页面不显示查看/回执按钮
    toJS(showReceipt).canView&&pathname!=='/calendar/detail/discussData'&&receiptBtn.push({
      key: 'canRead',
      text: getLabel(389531,'查看回执'),
      type: 'primary',
      onClick: () => {this.onReceipt({
        isPreview:'1',
        recordId:showReceipt.recepitId,
        canEdit:showReceipt.canEdit,
        memberType:1,
        prePathName: `${pathname}/receiptForm`,
      })},
    })

    toJS(showReceipt).canSubmit&&pathname!=='/calendar/detail/discussData'&&receiptBtn.push({
      key: 'canEdit',
      text: getLabel(500586,'提交回执'),
      type: 'primary',
      onClick: () => {this.onReceipt({
        isPreview:'0',
        recordId:showReceipt.recepitId,
        canEdit:showReceipt.canEdit,
        memberType:1,
        prePathName: `${pathname}/receiptForm`,
      })},
    })
    return receiptBtn;
  }

  //参会回执
  onReceipt = (params) =>{
    const { history , viewMeetingStore:{setState}} = this.props;
    setState({
      ...params
    })
    history.push('/calendar/detail/index/receiptForm');
  }

  //新建页面提交
  submit = (params)=>{
    const { submitMeeting ,setState, urlCreateParams } = this.props.viewMeetingStore;
    setState({type:'view'})
    params = {
      ...toJS(params),
      method:'submit',
      ismobile: '1'
    };
    if(urlCreateParams.isClose === 'true') {
      submitMeeting(params,() => {
        window.em.closeWindow&&window.em.closeWindow();
      });
     } else {
      submitMeeting(params,this.getDetail.bind(this,'submit'));
    }
  }

  //变更页面提交
  submitChangeMeeting = (params)=>{
    const { changemeeting , setState} = this.props.viewMeetingStore;
    
    alert(getLabel(15172, '系统提示'), getLabel(128674,'确定要进行会议信息变更吗？'), [
      { 
        text: getLabel(386789,'取消'), 
        onPress: () => {
          this.setOnLoading()
        }, 
        style: 'default' 
      },
      { 
        text: getLabel(386788,'确定'), 
        onPress: () => {
          setState({type:'view'})
          params = {
            ...toJS(params),
            ismobile: '1'
          };
          changemeeting(params,this.getDetail)
        } },
    ]);
  }

  //新建页面保存
  save = (params)=>{
    const { saveMeeting , setState, urlCreateParams} = this.props.viewMeetingStore;
    setState({type:'view'})
    params = {
      ...toJS(params),
      method:'save',
      ismobile: '1'
    };
    if(urlCreateParams.isClose === 'true') {
      saveMeeting(params,() => {
        window.em.closeWindow&&window.em.closeWindow();
      });
    } else {
      saveMeeting(params,this.getDetail.bind(this,'save'));
    }
  }

  //编辑页面保存
  edit = (params)=>{
    const { editMeeting , setState} = this.props.viewMeetingStore;
    setState({type:'view'})
    params = {
      ...toJS(params),
      ismobile: '1'
    };
    editMeeting(params,this.getDetail.bind(this,'edit'))

  }

  //跳转到变更页面
  changeMeeting = (meetingid)=>{
    this.setOnLoading(true)
    const { setState } = this.props.viewMeetingStore;
    setState({type:'change'})
    sessionStorage.setItem('type','change')
    const nowTabTemp = sessionStorage.getItem("meetingBaseNowTab");
    if(parseInt(nowTabTemp,10) > 0){
      this.setState({nowTab:0})
    }
    this.getDetail('change')
    this.setBaseDetail(true)
    this.setEditpageToViewpage();
  }

  //查看页面直接提交
  reSubmit2 = (meetingid)=>{
    const { reSubmit2 , setState} = this.props.viewMeetingStore;
    setState({type:'view'})
    reSubmit2({
      meetingid: meetingid,
    },this.getDetail.bind(this,'reSubmit2'))
  }

  //提前结束
  overMeeting = (meetingid)=>{
    this.setOnLoading(true)
    let { overMeeting } = this.props.viewMeetingStore;
    // alert(getLabel(15172, '系统提示'), getLabel(126004, '确定要提前结束会议吗？'), [
    //   { text: getLabel(386789, '取消'), onPress: () => { this.setOnLoading(); }, style: 'default' },
    //   {
    //     text: getLabel(386788, '确定'), onPress: () => overMeeting({
    //       meetingid: meetingid,
    //     }, this.getDetail)
    //   },
    // ]);

  }

  //会议决议
  onShowDecision = ()=>{
    const { setState } = this.props.viewMeetingStore;
    setState({isView:'0',prePathName: `/calendar/detail/decision/index`})
    sessionStorage.setItem("decisionIsView",0);
    this.props.history.push(`/calendar/detail/decision/index`)
  }

  //复制
  copy = (meetingid)=>{
    const { pathname } = this.props.location;
    this.setOnLoading(true)
    const { copyMeeting, setState} = this.props.viewMeetingStore;
    const nowTabTemp = sessionStorage.getItem("meetingBaseNowTab");
    if (pathname.indexOf('calendar/detail/serviceData') > -1 || pathname.indexOf('calendar/detail/topicData') > -1) {
    } else { // 在非会议议程，会议服务页面跳转到会议信息页面
      this.setState({nowTab:0});
    }
    // if(parseInt(nowTabTemp,10) > 2){
    //   this.setState({nowTab:0})
    // }
    copyMeeting({meetingid: meetingid},this.getDetail.bind(this,'copy'))
    setState({is_service: true,is_topic:true})
  }

  //取消会议
  cancelMeeting = (meetingid)=>{
    this.setOnLoading(true)
    let {cancelMeeting} = this.props.viewMeetingStore;
    alert(getLabel(15172, '系统提示'), getLabel(20117,'你确定要取消会议吗？'), [
      { text: getLabel(386789,'取消'), onPress: () => {this.setOnLoading();}, style: 'default' },
      { text: getLabel(386788,'确定'), onPress: () => cancelMeeting({
        meetingid: meetingid,
      },this.goBack) },
    ]);
  }

  //批准
  doSubmit = (meetingid) => {
    const { doSubmit } = this.props.viewMeetingStore;
    doSubmit({
      meetingid: meetingid,
    },this.goBack) 
  }

  //提交审批
  doSubmit2 = (meetingid) => {
    const { doSubmit2 } = this.props.viewMeetingStore;
    doSubmit2({
      meetingid: meetingid,
    },this.goBack) 
  }

  //退回
  doReject = (meetingid)=>{
    this.setOnLoading(true)
    const { doReject } = this.props.viewMeetingStore;
    alert('', getLabel(24247, '你确定要退回吗'), [
      { text: getLabel(386789,'取消'), onPress: () => {this.setOnLoading();}, style: 'default' },
      { text: getLabel(386788,'确定'), onPress: () => doReject({
        meetingid: meetingid,
      },this.goBack) },
    ]);
  }

  //提交审批
  reSubmit = (meetingid)=>{
    const { reSubmit } = this.props.viewMeetingStore;
    reSubmit({
      meetingid: meetingid,
    },this.goBack) 
  }

  //删除
  doDelete = (meetingid) =>{
    this.setOnLoading(true)
    const { doDelete } = this.props.viewMeetingStore;
    alert('', getLabel(127574, '确定删除吗？'), [
      { text: getLabel(386789,'取消'), onPress: () => {this.setOnLoading();}, style: 'default' },
      { text: getLabel(386788,'确定'), onPress: () => doDelete({
        meetingid: meetingid,
      },this.goBack) },
    ]);
  }

  getEdit = ()=>{
    this.setOnLoading(true)
    //设置跳转用
    this.setBaseDetail(true)
    const { setState } = this.props.viewMeetingStore;
    setState({type:'edit',is_service: true,is_topic:true}); // 编辑时，初始化is_service，is_topic

    sessionStorage.setItem('type','edit')
    this.getDetail('edit');
    this.setEditpageToViewpage();
  }

  setEditpageToViewpage = () => {// 解决编辑，变更页面跳转到会议的查看页面
    const _this = this;
    window.em && window.em.configNavigation && window.em.configNavigation({
      'left':{
        'name': getLabel(384083,'返回'), 
        'action':function(argument){ 
          const { type, setState } = _this.props.viewMeetingStore;
          const { pathname } = _this.props.location;
          if((pathname.indexOf("/detail/") > -1 && pathname.split('/').length === 4) && (type === 'edit' || type === 'change')) {
            setState({ type:'view' }, () => {
              _this.getDetail('editToView');
            });
            sessionStorage.setItem('type','view');
            window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(384485, '查看会议') })
            window.em && window.em.resetNavigation && window.em.resetNavigation();
          } else {
            window.history.go(-1);
          }
        },
      },
    });
  }

  setOnLoading = (flg=false)=> {
    const { setState } = this.props.viewMeetingStore;
    setState({onLoading:flg})
  }

  setBaseDetail = (flg=false)=> {
    const { setBaseDetail } = this.props.viewMeetingStore;
    setBaseDetail(flg)
  }

  getDetail = (type='')=>{
    const {  viewMeetingStore:{ getBtns , meetingId, getPreview}} = this.props;
    const { pathname } = this.props.location;
    this.setOnLoading();
    getBtns({meetingid:meetingId?meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''})
    const nowTabTemp = sessionStorage.getItem("meetingBaseNowTab")
    //复制的时候如果不是会议信息/会议议程/会议服务,那么就要跳转到index页面
    if(type === 'copy'){
      // if(parseInt(nowTabTemp,10) > 2){
      //   this.props.history.push("/calendar/detail/index")
      // }
      if (pathname.indexOf('calendar/detail/serviceData') > -1 || pathname.indexOf('calendar/detail/topicData') > -1) {
      } else { // 在非会议议程，会议服务页面跳转到会议信息页面
        this.props.history.push("/calendar/detail/index")
      }
    }
    //编辑下，保存完签到信息，跳转回会议信息
    //if(type == 'edit'){
      if (pathname.indexOf('calendar/detail/signcreate') > -1) {
        this.props.history.push("/calendar/detail/index")
      }
    //}

    //变更的时候如果不是会议信息那么就要跳转到index页面
    if(type === 'change'){
      const nowTabTemp = sessionStorage.getItem("meetingBaseNowTab")
      if(parseInt(nowTabTemp,10) > 0){
        this.props.history.push("/calendar/detail/index")
      }
    }
    if(parseInt(nowTabTemp,10) !== 0 && (type === 'reSubmit2' || type === 'submit' || type === 'save' || type === 'edit' || type === 'copy')){
      getPreview({meetingid:meetingId?meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''},this.editCondition)
    }
    if(type === 'editToView') {
      getPreview({meetingid:meetingId?meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''},this.editCondition)
    }
  }

  editCondition = ()=>{
    const { form ,} = this.props.viewMeetingStore;
    const { conditioninfo } = form;
    let values = form.formParams
    //判断会议类型
    let conditioninfoTemp = toJS(conditioninfo);
    let retconditioninfo = [];
    let groups = {};
    conditioninfoTemp.length!==0 && conditioninfoTemp.forEach((group) => {
      let fields = []
      group.items.forEach((field) => {
        if (field.domkey[0] === 'address') {
          if(values['address'] === '' && values['customizeAddress'] !== ''){
            field.browserConditionParam = {...field.browserConditionParam,viewAttr:2};
            field = {...field, rules: '',viewAttr: 2};
          }else if(values['address'] === '' && values['customizeAddress'] === ''){
            field.browserConditionParam = {...field.browserConditionParam,viewAttr:3};
            field = {...field,rules:'required',viewAttr:3};
          }
        }else if (field.domkey[0] === 'customizeAddress') {
          if(values['customizeAddress'] === '' && values['address'] !== ''){
            field = {...field,viewAttr:2,rules:''};
          }else if(values['address'] === '' && values['customizeAddress'] === ''){
            field = {...field,viewAttr:3,rules:'required'};
          }
        }
        fields.push(field)
      })
      groups = {...group,items:fields}
      retconditioninfo.push(groups)
    })
    form.setState({conditioninfo:retconditioninfo})
  }

  getHash = ()=> {
    return Math.random().toString(36).substr(2, 6);
  }

  goBack = ()=>{
    this.removesessionStorageItem();
    this.setOnLoading();
    const nowTabTemp = sessionStorage.getItem('meetingNowTab')
    if(nowTabTemp === '0'){
      this.props.history.push('/calendar/allMeeting')
    }else if(nowTabTemp === '1'){
      this.props.history.push('/calendar/endMeeting')
    }else if(nowTabTemp === '2'){
      this.props.history.push('/calendar/goingMeeting')
    }else if(nowTabTemp === '3'){
      this.props.history.push('/calendar/notStartMeeting')
    }else{
      // this.props.history.push('/calendar/allMeeting')
      if(window.em && localStorage.getItem('meetingDetailIsSingle') == 'true') {
        window.em.closeWindow&&window.em.closeWindow();
      } else {
        this.props.history.go(-1);
      }
    }
    const { initForm } = this.props.viewMeetingStore;
    initForm();
  }

}
